/**
 * 进一步对基础模块的导入提炼
 * 有关模块注册指导原则请参考：https://github.com/cipchk/ng-alain/issues/180
 */
import {
  NgModule,
  Optional,
  SkipSelf,
  ModuleWithProviders,
} from '@angular/core';
import { RouteReuseStrategy } from '@angular/router';

import { AlainThemeModule } from '@delon/theme';
import { DelonABCModule, ReuseTabService, ReuseTabStrategy } from '@delon/abc';


import { PageHeaderConfig, STConfig } from '@delon/abc';
export function pageHeaderConfig(): PageHeaderConfig {
  return Object.assign(new PageHeaderConfig(), { home_i18n: '主页', autoBreadcrumb: false });
}
export function stConfig(): STConfig {
  return Object.assign(new STConfig(), { page: { front: false, total: true, showSize: true }, size: 'small', bordered: true, scroll: { x: '900px' } });
}

import { DelonAuthConfig } from '@delon/auth';
export function delonAuthConfig(): DelonAuthConfig {
  return Object.assign(new DelonAuthConfig(), <DelonAuthConfig>{
    login_url: '/passport/login',
  });
}

// endregion

@NgModule({
  imports: [
    AlainThemeModule.forRoot(),
  ],
})
export class DelonModule {
  constructor(
    @Optional()
    @SkipSelf()
    parentModule: DelonModule,
  ) { }

  static forRoot(): ModuleWithProviders {
    return {
      ngModule: DelonModule,
      providers: [
        {
          provide: RouteReuseStrategy,
          useClass: ReuseTabStrategy,
          deps: [ReuseTabService],
        },
        // TIPS：@delon/abc 有大量的全局配置信息，例如设置所有 `simple-table` 的页码默认为 `20` 行
        { provide: STConfig, useFactory: stConfig },
        { provide: PageHeaderConfig, useFactory: pageHeaderConfig },
        //{ provide: DelonAuthConfig, useFactory: delonAuthConfig },
      ],
    };
  }
}
